package edu.java.homework.hw08.ipj10.exer01done;

public class MusicShop extends Firm {

    // --- Instance Variables --------------------------------------------------
    MusicAlbum[] albums = null;

    // --- Constructors --------------------------------------------------------
    public MusicShop(String name, double profit, Worker[] workers,
	    MusicAlbum[] albums) {
	super(name, profit, workers);
	setAlbums(albums);
    }

    // --- Getters and Setters -------------------------------------------------

    public MusicAlbum[] getAlbums() {
	return albums;
    }

    public void setAlbums(MusicAlbum[] albums) {
	// check array reference for Null-pointer Exception
	if (albums == null) {
	    throw new IllegalArgumentException(
		    "The array of MisucAlbum objects is null-pointed.");
	}
	// check each of the array elements for null pointer exception
	for (MusicAlbum musicAlbum : albums) {
	    if (musicAlbum == null) {
		throw new IllegalArgumentException(
			"The musicAlbum object is null pointed");
	    }
	}

	this.albums = albums;
    }

    // --- Methods -------------------------------------------------------------

    @Override
    public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append(super.toString());
	sb.append(printMusicAlbumsInfo());

	return sb.toString();

    }

    private String printMusicAlbumsInfo() {
	StringBuilder sb = new StringBuilder();
	MusicAlbum[] ma = getAlbums();
	for (MusicAlbum album : ma) {
	    sb.append(album.toString() + "\n");
	}
	return sb.toString();
    }
}
